//-----------------------------------------部门处理----------------------------------------------------

/**
 * 添加部门事件
 */
$("#addDept").live( "pageinit" , function(event){
	
	$("#addDeptBtn").click(function(event){
		var name = $("#deptName").val();
		var id = $("#deptId").val();
		
		if( !( valiateIdBetwwn(id) ) ){
			$.mobile.changePage( $("#idErrorDialog") ,{ transition : "pop" ,changeHash: false ,  reloadPage : true  } );
			return false;
		}
		
		if( !( regIdInt( id ) )  ){
			$.mobile.changePage( $("#idErrorDialog") , { transition : "pop" ,changeHash: false ,  reloadPage : true  } );
			return false;
		}
		
		if(  !( nameValidate(name) )  ){
			$.mobile.changePage( $("#nameErrorDialog") ,{ transition : "pop" ,changeHash: false ,  reloadPage : true  });
			return false;
		}
		
		//start ajax submit
		var url = "mobile/deptServlet";
		var para = {deptId : $("#deptId").val(),			
				    deptName : name,
				    method: 'add'};
		var returnType = "text";		
		
		ajaxPost( url , para , callBack , returnType );
		
		//回调函数
		function callBack(data){
			if( data == "success" ){
				$.mobile.changePage( "success.jsp" ,{ transition : "pop" ,changeHash: false ,  reloadPage : true  } );
			}else{
				$.mobile.changePage( $("#idRepeatDialog") , { transition : "pop" ,changeHash: false ,  reloadPage : true  });
			}	
		} //end callBack		
	});
}); 



$("#addDept").live( "pageshow" , function(event){
	var url = "mobile/deptServlet";
	var para = { 
					method : 'countNextId',
					time : new Date().getTime()
				};
	var retunType = "text";
	function callBack(data){
		$("#deptId").attr("value",data);
	}	
	
	$.post( url , para , callBack,retunType );	//閼惧嘲褰囨稉瀣╃閺夘摨d閻ㄥ嫬锟�
});




/**
 * 修改部门事件
 */
$('#editDept').live( "pageinit" , function(event){
		var obj ;
		
		//获取所有的部门详情
		var url = "mobile/deptServlet";
			$.post( url , {
				method : 'getAllDept',
				time : new Date().getTime()
			} , function(data){
				obj = data;
				
				$.each( obj ,function(index,dept){
					$("#deptId").append( "<option value='"+dept.deptId+"'>"+ dept.deptName +"</option>" );					
				});
			} ,"json"  );	

	
			$("#deptId").bind( "change", function(event) {  
	          	var id = $(this).val() ;
	          	
	          	if( id == "--" ){
	          		$("#deptName").attr( "value","" );
	          	}
	          	
	          	$.each( obj , function(index,dept){
	          		if( id == dept.deptId ){
	          			$("#deptName").attr( "value",dept.deptName );
	          		}	          		
	          	}); 
      		  });
      		  

      		  $("#updateDeptBtn").click(function(event){
      		  		var id = $("#deptId").val();
      		  		var name = $("#deptName").val();
      		  		
      		  		if( id == "--" ){
      		  			$.mobile.changePage( $("#idSelectErrorDialog") ,{ transition : "pop" ,changeHash: false ,  reloadPage : true  } );
      		  			return false;
      		  		}
      		  		
      		  		if( name.length <= 0 ){
      		  			$.mobile.changePage( $("#nameErrorDialog") ,{ transition : "pop" ,changeHash: false ,  reloadPage : true  });
      		  			return false;
      		  		}
      		  		
      		  		var url = "mobile/deptServlet";
      		  		$.post( url, {
      		  			deptId : id,
      		  			deptName : name,
      		  			method : 'update'
      		  		},function(data){
      		  			if( data == "success" ){
      		  				$.mobile.changePage( "success.jsp" ,{ transition : "pop" ,changeHash: false ,  reloadPage : true  } );
      		  			}else{
      		  				$.mobile.changePage( "error.jsp" ,{ transition : "pop" ,changeHash: false ,  reloadPage : true  } );
      		  			}
      		  		},"text" );
				
      		  });		  
} );

/**
 * 显示所有部门列表事件,此事件不同,是调用每次显示组件时都异步调用获取数据
 */
$("#PayrollDepartmentList").live( "pageshow" , function(event){
	
	var url = "PayrollDepartmentServlet";
	var UserID= document.from1.UserID.value;
	$.post( url , {
		method : 'getAll',
		time : new Date().getTime(),
		UserID : UserID
	} , function(data){		
		
		$.each( data , function(index,payrollDepartment){
			$("#report").append("<div data-role='collapsible'>" +
					"<h1>日期："+ payrollDepartment.postdate +"</h1>" +
							"<table width='100%'> " +
							"<tbody id='txt'> " +
							"<tr><td ><b> 皮坯接收:"+ payrollDepartment.rcveweight +"吨 &nbsp"+ payrollDepartment.rcveweight +"张</b></td>" +
									"</tr><tr><td colspan='1'><hr></td></tr>" +
			"<tr><td><b> 皮坯在制品:"+ payrollDepartment.rcveweight +"张</b></td>" +
			"</tr><tr><td colspan='1'><hr></td></tr>" +
			"<tr><td><b> 皮坯移交: "+ payrollDepartment.rcveweight +"张</b></td>" +
			"</tr><tr><td colspan='1'><hr></td></tr>" +
			"<tr><td><b> 皮坯月累计: "+ payrollDepartment.rcveweight +"吨</b></td>" +
			"</tr><tr><td colspan='1'><hr></td></tr>" +
			"<tr><td><b> 今日工资:"+ payrollDepartment.rcveweight +"</b></td>" +
			"</tr><tr><td colspan='1'><hr></td></tr>" +
			"<tr><td><b> 本月累计工资:"+ payrollDepartment.rcveweight +"</b></td>" +
			"</tr><tr><td colspan='1'><hr></td></tr>" +
			"<tr><td><b> 单位成本工资:"+ payrollDepartment.rcveweight +"</b></td>" +
			"</tr><tr><td colspan='1'><hr></td></tr>" +
			"<tr><td><b> 上月成本工资:"+ payrollDepartment.rcveweight +"</b></td>" +
			"</tr><tr><td colspan='1'><hr></td></tr>" +
			"<tr><td><b> 2013年平均工资:"+ payrollDepartment.rcveweight +"</b></td>" +
			"</tr><tr><td colspan='1'><hr></td></tr>" +
			"<tr><td><b> 2014年平均工资:"+ payrollDepartment.rcveweight +"</b></td>" +
			"</tr><tr><td colspan='1'><hr></td></tr>" +
			"<tr><td><b> 异常工资:"+ payrollDepartment.rcveweight +"</b></td>" +
			"</tr><tr><td colspan='1'><hr></td></tr>" +
			"</tbody>" +
			"</table>" +
			"</div>");
		   $('#report').trigger("create");
			
		});
		
	} ,"json" );// end page create event	
});

//$("#PayrollDepartmentList").live( "pageshow" , function(event){
//	var payrollDepartment_rcveweight=1;
//	var payrollDepartment_postdate=2;
//  //$("#report").append("<div data-role='collapsible'><h1>日期</h1><table width='100%'> <tbody id='txt'> <tr><td align='center'><b> + payrollPersonal.postdate+ </b></td><td align='center'><b> + payrollPersonal.rcvenum+ </b></td><td align='center'><b>+ payrollPersonal.transnum +</b></td></tr><tr><td colspan='3'><hr></td></tr><tr><td align='center'><b> + payrollPersonal.postdate+ </b></td><td align='center'><b> + payrollPersonal.rcvenum+ </b></td><td align='center'><b>+ payrollPersonal.transnum +</b></td></tr><tr><td colspan='3'><hr></td></tr></tbody></table> </div><div data-role='collapsible'><h1>点击我 - 我可以折叠！</h1><p>我是被展开的内容。</p></div>");
//	$("#report").append("<div data-role='collapsible'>" +
//			"<h1>日期："+ payrollDepartment_postdate +"</h1>" +
//					"<table width='100%'> " +
//					"<tbody id='txt'> " +
//					"<tr><td ><b> 皮坯接收:"+ payrollDepartment_rcveweight +"吨 &nbsp"+ payrollDepartment_rcveweight +"张</b></td>" +
//							"</tr><tr><td colspan='1'><hr></td></tr>" +
////	"<tr><td ><b> 皮坯接收:"+ payrollDepartment_rcveweight +"张</b></td>" +
////	"</tr><tr><td colspan='1'><hr></td></tr>" +
//	"<tr><td><b> 皮坯在制品:"+ payrollDepartment_rcveweight +"张</b></td>" +
//	"</tr><tr><td colspan='1'><hr></td></tr>" +
//	"<tr><td><b> 皮坯移交: "+ payrollDepartment_rcveweight +"张</b></td>" +
//	"</tr><tr><td colspan='1'><hr></td></tr>" +
//	"<tr><td><b> 皮坯月累计: "+ payrollDepartment_rcveweight +"吨</b></td>" +
//	"</tr><tr><td colspan='1'><hr></td></tr>" +
//	"<tr><td><b> 今日工资:"+ payrollDepartment_rcveweight +"</b></td>" +
//	"</tr><tr><td colspan='1'><hr></td></tr>" +
//	"<tr><td><b> 本月累计工资:"+ payrollDepartment_rcveweight +"</b></td>" +
//	"</tr><tr><td colspan='1'><hr></td></tr>" +
//	"<tr><td><b> 单位成本工资:"+ payrollDepartment_rcveweight +"</b></td>" +
//	"</tr><tr><td colspan='1'><hr></td></tr>" +
//	"<tr><td><b> 上月成本工资:"+ payrollDepartment_rcveweight +"</b></td>" +
//	"</tr><tr><td colspan='1'><hr></td></tr>" +
//	"<tr><td><b> 2013年平均工资:"+ payrollDepartment_rcveweight +"</b></td>" +
//	"</tr><tr><td colspan='1'><hr></td></tr>" +
//	"<tr><td><b> 2014年平均工资:"+ payrollDepartment_rcveweight +"</b></td>" +
//	"</tr><tr><td colspan='1'><hr></td></tr>" +
//	"<tr><td><b> 异常工资:"+ payrollDepartment_rcveweight +"</b></td>" +
//	"</tr><tr><td colspan='1'><hr></td></tr>" +
//	"</tbody>" +
//	"</table>" +
//	"</div>");
//   $('#report').trigger("create");
//   
//});